<template>
	<view class="s-page-wrapper">
		<view class="search-pop">
			<view class="top-input row between" >
				<u-icon name="search"></u-icon>
				<input type="text" value="" :focus="true" confirm-type="search" placeholder-style="color:#74738e;font-size:26upx;" placeholder="请输入关键词"
				 v-model="keywords" @confirm="submitSearch" />
				 <view class="btn" hover-class="hover-opacity" @tap="submitSearch">
				 	搜索
				 </view>
			</view>
		</view>
		<view class="search-cat" v-if="searchList.length!=0">
			<view class="search-cat-tit"><text class="up-menu">历史搜索</text>
				<image src="/static/img/chanchu2.png" class="del-img" @tap="openClearTips"></image>
			</view>
			<view class="src-content">
				<view class="src-item clamp" v-for="(v, k) in searchList" :key="k" @tap="hostSearch(v)">
					{{v}}
				</view>
			</view>
		</view>
		<mix-modal ref="mixModal" text="确定删除吗?" title="温馨提示" @onConfirm="clear"></mix-modal>

	</view>
</template>

<script>
	import mixModal from "@/components/mix-modal/mix-modal.vue"
	export default {
		components:{
			mixModal
		},
		data() {
			return {
				keywords: '',
				searchList: [],
				hotList: []
			};
		},
		onShow() {
			uni.getStorageSync('historySearch') ? this.searchList = uni.getStorageSync("historySearch") : this.searchList = [];
		},
		methods: {
			openClearTips(){
				this.$refs.mixModal.open();
			},
			submitSearch() {
				if(this.keywords == ""){
					this.$util.msg("请输入要搜索的内容!");
					return
				}
				
				this.searchList.forEach((item,index)=>{
					if(item==this.keywords){
						this.searchList.splice(index, 1)
					}
				})
				if(this.searchList.length > 5){
					this.searchList.pop()
				}
				this.searchList.unshift(this.keywords);
				uni.setStorageSync("historySearch", this.searchList);
				this.navTo(`/pages/search/search_list?name=${this.keywords}`)
			},
			clear() {
				this.searchList = [];
				uni.removeStorageSync("historySearch");
				this.$util.msg('删除成功!')
			},
			hostSearch(v) {
				this.keywords = v;
				this.submitSearch();
			}
		},
		onHide() {
			this.keywords = ''
		}
	};
</script>
<style>
	page {
		background-color: #FFFFFF;
	}
</style>

<style lang="scss">
	.btn{
		width:141upx;
		height: 64upx;
		text-align: center;
		line-height: 64upx;
		background: #FFD6D6;
		border-radius: 32upx;
		font-size: 26upx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #CC1313;
	}
	.del-img {
		width: 30upx;
		height: 30upx;
	}

	.red {
		color: #FF0000;
	}

	.search-img {
		width: 38upx;
		height: 38upx;
	}

	.uni-icon-search {
		font-size: 30upx;
	}

	.help-tips {
		font-size: 26upx;
		color: #999;
		line-height: 26upx;
		padding: 0 0 0 30upx;
		margin: 0;
		width: 80%;
		text-align: left;
	}

	.help-tips.color999 {
		color: #999999;
	}
	.search-pop {
		padding: 20upx;
		display: flex;
		justify-content: space-between;
		align-items: center;

	}

	.top-input {
		flex: 1;
		height: 70upx;
		line-height: 70upx;
		background-color: #F6F6F6;
		border-radius:35upx;
		color: #74718c;
		padding-left: 35upx;
	}

	.top-input input {
		height: 100%;
		width: 100%;
		padding-left:16upx;
	}

	.search-btn {
		height: 100%;
		color: #333333;
		font-size: 27upx;
	}

	.search-cat {
		padding:20upx;
		background: #FFFFFF;
	}

	.search-cat .search-cat-tit {
		position: relative;
		display: flex;
		align-items: center;
		font-weight: bold;
		justify-content: space-between;
	}

	.search-cat .search-cat-tit .up-menu {
		font-size: 30upx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
		line-height: 55upx;
	}

	.src-content {
		margin:20upx auto;
		display: flex;
		flex-wrap: wrap;
	}

	.src-item {
		width: 23%;
		border-radius: 10upx;
		padding: 7upx 20upx;
		border: 1px solid #D0D0D0;
		margin: 20upx 10upx;
		position: relative;
		font-size: 26upx;
		color: #666666;
		text-align: center;
	}

	.clear-search {
		padding: 10px 0;
		text-align: center;
		font-size: 30upx;
		color: #333;
	}
</style>
